<?php

/**
 *  +---------------------------------------------------------------------- 
 *  | 文件功能：程序API路由
 *  +---------------------------------------------------------------------- 
 *  | Copyright (c) 2022~2024 https://www.huihuiv.com All rights reserved.
 *  +---------------------------------------------------------------------- 
 *  | Create At: 2024年02月26日 18:12:38
 *  +---------------------------------------------------------------------- 
 *  | Author: 半壶水 <star@cqshanwen.com>
 *  +---------------------------------------------------------------------- 
 */

use App\Http\Controllers\Api\AuthController;
use App\Http\Controllers\Api\CategoryController;
use App\Http\Controllers\Api\ContentSimplecontroller;
use App\Http\Controllers\Api\FileController;
use App\Http\Controllers\Api\GroupController;
use App\Http\Controllers\Api\HomeController;
use App\Http\Controllers\Api\PasswordTypeController;
use App\Http\Controllers\Api\SettingController;
use App\Http\Controllers\Api\ToolsPasswordController;
use App\Http\Controllers\Api\UserController;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "api" middleware group. Make something great!
|
*/

/**
 * 无需权限校验路由
 */
Route::group(['prefix' => 'v1'], function () {
    // 用户注册
    Route::post('/user/register', [UserController::class, 'register']);
    // 用户登录
    Route::post('/user/login', [UserController::class, 'login']);
    // 获取分类列表
    Route::get('/category/list/{flag}', [CategoryController::class, 'query']);
    // 获取/请求站点信息
    Route::get('/setting/query/{flag}', [SettingController::class, 'query']);

    // 获取首页banner
    Route::get('/content/get_swiper_list/{num}', [HomeController::class, 'get_swiper_list']);

    // 获取内容列表
    Route::get('/content/list/{flag}/{page}/{size}', [ContentSimplecontroller::class, 'query']);
    // 按flag获取列表内容
    Route::get('/content/list/{flag}/{num}', [ContentSimplecontroller::class, 'query']);
    // 按flag获取前后N条数据
    Route::get('/content/{flag}/{cs_id}/{num}', [ContentSimplecontroller::class, 'query']);
    // 获取文章正文
    Route::get('/content/{flag}/{cs_id}', [ContentSimplecontroller::class, 'query']);
});

/**
 * 需要权限校验的路由
 */
Route::group(['middleware' => 'auth.check', 'prefix' => 'v1'], function () {
    // 刷新token
    Route::get('/user/refresh_token', [UserController::class, 'refresh_token']);
    // 注销登录
    Route::get('/user/logout', [UserController::class, 'logout']);
    // 获取当前用户信息
    Route::get('/user/get_self_info', [UserController::class, 'get_self_info']);
});

/**
 * 管理后台专用路由
 */
Route::group(['middleware' => 'auth.check', 'prefix' => 'v1/manager'], function () {
    // 创建/修改用户组
    Route::post('/group/create', [GroupController::class, 'create']);
    // 获取用户组列表
    Route::get('/group/list/{flag}', [GroupController::class, 'query']);
    // 启用/禁用用户组
    Route::post('/group/status', [GroupController::class, 'status']);

    // 创建/修改权限菜单
    Route::post('/auth/create', [AuthController::class, 'create']);
    // 获取权限菜单列表
    Route::get('/auth/list/{flag}', [AuthController::class, 'query']);
    // 删除权限菜单
    Route::post('/auth/delete', [AuthController::class, 'delete']);

    // 创建用户
    Route::post('/user/create', [UserController::class, 'create']);
    // 获取用户列表
    Route::get('/user/list/{flag}/{page}/{size}', [UserController::class, 'query']);
    // 获取某个用户资料详情
    Route::get('/user/{flag}/{uid}', [UserController::class, 'query']);
    // 启用/禁用用户
    Route::post('/user/status', [UserController::class, 'status']);

    // 创建/修改分类
    Route::post('/category/create', [CategoryController::class, 'create']);
    // 删除分类
    Route::post('/category/delete', [CategoryController::class, 'delete']);

    // 创建/修改站点信息
    Route::post('/setting/create', [SettingController::class, 'create']);

    // 发布内容 
    Route::post('/content/create', [ContentSimplecontroller::class, 'create']);

    // 上传文件到ColudFlare
    Route::post('/file/cloud_flare/upload', [FileController::class, 'upload_2_cloud_flare']);

    // 获取密码类型
    Route::get('/tools/password/query/password_type/{flag}', [PasswordTypeController::class, 'query']);

    // 创建密码信息
    Route::post('/tools/password/create', [ToolsPasswordController::class, 'create']);
});
